<?php
require('../config.php');
		$start=0;
		$num=10;
		if(isset($_REQUEST['start'])) $start=$_REQUEST['start'];
		if(isset($_REQUEST['num'])) $num=$_REQUEST['num'];
		$cateId='';
		$cateName='';
		if(isset($_REQUEST['cateName'])) $cateName=$_REQUEST['cateName'];
		if(isset($_REQUEST['cateId'])) $cateId=$_REQUEST['cateId'];
		$paixu=$_REQUEST['paixu'];
		$sql="select s.id,s.sid,s.shop_id,s.title,s.qishu,s.thumb,s.zongrenshu,s.canyurenshu,s.shenyurenshu,s.yunjiage from `".$oto."_shoplist` as s where `shenyurenshu`>0 and `q_end_time` is null  ";
		if($cateId!='')
		{
			if($cateId!='0')
			{
				$sql.=" and (`mall_cateid2`='$cateId' or `mall_cateid3`='$cateId') ";
			}
		}
		else if($cateName!='')
		{
			if($cateName!='所有商品')
			{
				$sql_cate="select * from `".$oto."_goods_cats` as g where catFlag='1' and isFixed='0'  LIKE '%$cateName%' ";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$goods_cats[]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(isset($goods_cats))
				{
					$cateId=$goods_cats[0]['catId'];
					$sql.=" and (`mall_cateid2`='$cateId' or `mall_cateid3`='$cateId') ";
				}
			}
		}

		if($paixu=='jjjx')
		{
			$sql.=" order by shenyurenshu asc ";
		}
		else if($paixu=='lastnew')
		{
			$sql.=" order by `time` desc ";
		}
		else if($paixu='renqi')
		{
			$sql.=" and  s.`pos`=1 and s.`renqi`=1 ";
		}
		else if($paixu='money')
		{
			$sql.=" order by money asc ";
		}

		$sql.=" limit $start,$num";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$shoplist[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($shoplist))
		{
			for($i=0;$i<count($shoplist);$i++)
			{
				$sid=$shoplist[$i]['sid'];
				//获取期数
				$sql="select s.qishu from `".$oto."_shoplist` as s where sid='{$sid}' order by qishu desc limit 1";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$qishu_info=$row;
				}
				if(isset($qishu_info)) $shoplist[$i]['max_qishu']=$qishu_info['qishu'];
				else $shoplist[$i]['max_qishu']="";
			}
		}
		if(isset($shoplist)) echo json_encode($shoplist);
		else echo '[]';
?>